/**
 * MIT License
 * 
 * Copyright (c) 2024 - present @ ebraid
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __EB_SIMPLE_BUS_H__
#define __EB_SIMPLE_BUS_H__


struct simple_driver;


struct simple_device {
    list_node_t  entry;
    const char  *compatible;
    struct simple_driver *driver;
    void        *io_base;
    const void  *platform_data;
    const void  *private_data;
};


struct simple_driver {
    list_node_t  entry;
    int (*probe)(struct simple_device *dev);
    void (*remove)(struct simple_device *dev);
    struct match_id  *id_table;
};


#ifdef __cplusplus
extern "C" {
#endif


int simple_device_register(struct simple_device *dev);
void simple_device_unregister(struct simple_device *dev);
int simple_driver_register(struct simple_driver *drv);
void simple_driver_unregister(struct simple_driver *drv);


static inline const void* simple_get_platform_data(struct simple_device *sdev)
{
    return sdev->platform_data;
}


static inline void simple_set_platform_data(struct simple_device *sdev, void *data)
{
    sdev->platform_data = data;
}


static inline const void* simple_get_private_data(struct simple_device *sdev)
{
    return sdev->private_data;
}


static inline void simple_set_private_data(struct simple_device *sdev, void *data)
{
    sdev->private_data = data;
}


#ifdef __cplusplus
}
#endif


#endif //!__EB_SIMPLE_BUS_H__